#include<bits/stdc++.h>
using namespace std;
long long t;
map<long long,long long> mp;
long long n;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        mp.clear();
        for(long long i=0;i<n;i++){
            long long l;
            cin>>l;
            mp[l]++;
        }
        long long ans=0;
        for(map<long long,long long>::iterator it=mp.begin();it!=mp.end();it++){
            ans+=it->first*(it->second-1);
        }
        cout<<ans<<endl;
    }
    return 0;
}
